<template>
  <div class="links-box" ref="linksBox" @mouseover="mouseover" @mouseleave="mouseLeave" @mousedown="mousedown"
       @mousemove="mousemove" @mouseup="mouseup">
    <div class="move-btn left-btn" v-show="showLeftBtn&&showBtn" :style="{backgroundColor: colorName}"
         @click="moveLeft">
      <i class="el-icon-back"></i>
    </div>
    <ul class="links-main" ref="linksMain" :style="`left: ${domLeft}px`">
      <li class="links-item" @click="showMessage">已结算查询</li>
      <li class="links-item" @click="showMessage">交易明细</li>
      <li class="links-item" @click="showMessage">结算数据</li>
      <li class="links-item" @click="showMessage">对账通知书</li>

      <li class="links-btn" @click="showMessage">
        <i class="el-icon-plus" :style="{color:colorName}"></i>
      </li>
    </ul>
    <div class="move-btn right-btn" v-show="showRightBtn&&showBtn" :style="{backgroundColor: colorName}"
         @click="moveRight">
      <i class="el-icon-right"></i>
    </div>
  </div>
</template>

<script>
    import {mapGetters} from "vuex";

    export default {
        name: "shortcutLinks",
        data() {
            return {
                domLeft: 0,
                showLeftBtn: true,
                showRightBtn: true,
                showBtn: false,
                linksMainWidth: 0,
                linksBoxWidth: 0,
                isMove: false,
                mouseDownLeftPoint: 0
            }
        },
        computed: {
            ...mapGetters(["colorName"]),
        },
        mounted() {
            this.getDomWidth()
        },
        watch: {
        },
        methods: {
            showMessage() {
                this.$confirm("功能建设中，敬请期待。", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "success"
                })
            },
            getDomWidth() {
                this.linksMainWidth = this.$refs.linksMain.clientWidth
                this.linksBoxWidth = this.$refs.linksBox.clientWidth
                // if (this.linksMainWidth > this.linksBoxWidth) {
                //     this.showLeftBtn = true
                // }
            },
            moveLeft() {
                let {domLeft, linksMainWidth, linksBoxWidth} = this
                if ((linksBoxWidth - domLeft - linksMainWidth) > (linksBoxWidth / 2)) {
                    // this.showLeftBtn = false;
                    return
                }
                this.domLeft -= 100
            },
            moveRight() {
                if (this.domLeft >= 0) {
                    return
                }
                this.domLeft += 100
            },
            mouseover() {
                this.showBtn = true
            },
            mouseLeave() {
                this.showBtn = false
            },
            mousedown() {
                //TODO
                //实现拖动 bug太多 暂时屏蔽
                // this.mouseDownLeftPoint = e.clientX
                // this.isMove = true
            },
            mouseup() {
                // this.isMove = false;
            },
            mousemove(e) {
                if (this.isMove) {
                    // console.log(e.offsetX)
                    this.domLeft += e.clientX - this.mouseDownLeftPoint
                    this.mouseDownLeftPoint = e.clientX
                }

            }
        }
    }
</script>

<style lang="scss" scoped>
  .links-box {
    width: 100%;
    height: 64px;
    background-color: white;
    border-radius: 10px;
    position: relative;
    overflow: hidden;

    .move-btn {
      width: 40px;
      height: 64px;
      background-color: #00a680;
      position: absolute;
      top: 0;
      z-index: 1000;
      color: white;
      display: flex;
      justify-content: center;
      align-items: center;
      transition: opacity .3s;
    }

    .left-btn {
      left: 0;
    }

    .right-btn {
      right: 0;
    }

    .links-main {
      z-index: 999;
      margin: 0;
      padding: 0 30px;
      height: 26px;
      align-items: center;
      position: absolute;
      left: 0;
      top: 19px;
      white-space: nowrap;
      display: inline-block;
      transition: all .3s;

      .links-item {
        display: inline-block;
        list-style: none;
        border: 1px solid #D4D4D4;
        padding: 0px 15px;
        font-size: 14px;
        height: 26px;
        line-height: 26px;
        color: #999999;
        border-radius: 10px;
        margin-right: 8px;
        word-wrap: normal;
      }

      .links-btn {
        display: inline-block;
        list-style: none;
        border: 1px solid #D4D4D4;
        width: 26px;
        height: 26px;
        border-radius: 10px;
        text-align: center;
        line-height: 26px;
        color: #999999;
      }
    }
  }
</style>
